<?php
header('Content-Type: text/xml');
$dom = new DOMDocument();
$link = mysql_connect("localhost","root","1234");
mysql_select_db("mobile", $link) or die("Could not find database.");

$result = mysql_query("SELECT * FROM user ") or die("Data not found.");

////////// Create the root  element
$userlist = $dom->createElement('userlist');
$dom->appendChild($userlist);

////////// Create the child  element

while ($row = mysql_fetch_array($result)) 
{
	$user = $dom->createElement('user');
	$userlist->appendChild($user); 
	//$order->setAttribute("type","it");

	$id = $dom->createElement('id');
	$user->appendChild($id);
	$idtext = $dom->createTextNode($row[0]);
	$id->appendChild($idtext);

	$username = $dom->createElement('username');
	$user->appendChild($username);
	$usernametext = $dom->createTextNode($row[1]);
	$username->appendChild($usernametext);
	
	$password= $dom->createElement('password');
	$user->appendChild($password);
	$passwordtext = $dom->createTextNode($row[2]);
	$password->appendChild($passwordtext);
	
	$location = $dom->createElement('location');
	$user->appendChild($location);
	$locationtext = $dom->createTextNode($row[3]);
	$location->appendChild($locationtext);
	
	$latitude = $dom->createElement('latitude');
	$user->appendChild($latitude);
	$latitudetext = $dom->createTextNode(($row[4]));
	$latitude->appendChild($latitudetext);

	$longtitude = $dom->createElement('longtitude');
	$user->appendChild($longtitude);
	$longtitudetext = $dom->createTextNode(($row[5]));
	$longtitude->appendChild($longtitudetext);

	$tel = $dom->createElement('tel');
	$user->appendChild($tel);
	$teltext = $dom->createTextNode(($row[6]));
	$tel->appendChild($teltext);

}



$xmlString = $dom->saveXML();
$dom->save("user.xml");
$xmlString = ltrim(substr($xmlString, strpos($xmlString,'?'.'>')+2));
echo $xmlString;



?>